<template>
    <div>
        <div class="info-form">
            <el-form :model="addForm" :inline="true">
                <el-form-item label="课程:">
                    <el-input v-model="addForm.lname"></el-input>
                </el-form-item>
                <el-form-item label="状态:">
                    <el-select v-model="value" placeholder="必修" style="width: 100px;" class="goodstype-input">
                        <el-option
                                style="width: 100px;"
                                v-for="item in options"
                                :key="item.value"
                                :label="item.label"
                                :value="item.value">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitForm()">提交</el-button>
                </el-form-item>
            </el-form>
        </div>
        <div>
            <el-table
                    :data="tableData"
                    stripe
                    style="width: 100%">
                <el-table-column
                        prop="lname"
                        label="课程">
                </el-table-column>
                <el-table-column
                        prop="status"
                        label="状态">
                </el-table-column>
                <el-table-column
                        prop="create_time"
                        label="创建时间">
                </el-table-column>
                <el-table-column label="操作">
                    <template scope="scope">
                        <el-button @click="handleClick(scope.$index)" type="text" size="small">查看</el-button>
                        <el-button @click.native.prevent="deleteRow(scope.$index, items)" type="text" size="small"> 删除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
        </div>
    </div>
</template>

<script>
    import moment from 'moment';
    export default {
        data() {
            return {
                options: [{
                    value: '1',
                    label: '必修'
                }, {
                    value: '0',
                    label: '选修'
                }],
                value: '1',
                addForm: {},
                tableData: []
            }
        },
        activated(){
            this.get();
        },
        methods: {
            submitForm(){
                let self = this;
                let lessons = this.addForm;
                lessons.state = this.value;
                this.$axioxs.post("/lessons/save", lessons)
                    .then(function (res) {
                        self.get();
                    })
            },
            get(){
                let self = this;
                this.$axioxs.get("/lessons/get")
                    .then(function (res) {
                        self.tableData = res.data.records;
                        self.tableData.forEach(item => {
                            item.create_time = moment(item.create_time).format("YYYY-MM-DD HH:mm");
                            if (item.state) {
                                item.status = "必修";
                            } else {
                                item.status = "选修"
                            }
                        })
                    })
            },
            handleClick(index) {

            },
            deleteRow(index, rows) {

            }
        }
    }
</script>